package ciprian.google;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

public class MyDialog extends DialogFragment {
    public static final int DIALOG_TYPE_AUTH_WAITING = 0;
    public static final int DIALOG_TYPE_ADD_POI = 1;

    public static final String DIALOG_TYPE = "type";
    int mType;
    Context mContext;

    /**
     * Create a new instance of MyDialogFragment, providing "num" as an
     * argument.
     */
    static MyDialog newInstance(int type) {
        MyDialog f = new MyDialog();

        // Supply num input as an argument.
        Bundle args = new Bundle();
        args.putInt(DIALOG_TYPE, type);
        f.setArguments(args);

        return f;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mType = getArguments().getInt(DIALOG_TYPE);

        // Pick a style based on the num.
        int style = DialogFragment.STYLE_NORMAL;
        int theme = android.R.style.Theme_Holo;

        setStyle(style, theme);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        int type = getArguments().getInt(DIALOG_TYPE);

        switch (type) {
        case DIALOG_TYPE_AUTH_WAITING:
            ProgressDialog waitingDialog = new ProgressDialog(getActivity());
            waitingDialog.setMessage(getText(R.string.ui_activity_authenticating));
            waitingDialog.setIndeterminate(true);
            waitingDialog.setCancelable(true);
            waitingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    ((AuthenticatorActivity) getActivity()).onWaitingDialogCancel();
                }
            });
            return waitingDialog;

        case DIALOG_TYPE_ADD_POI:
            // TODO: implement this when MapActivity will inherit
            // FragmentActivity
            return null;
        }

        return null;
    }
}
